﻿@model rentit03_client.Controllers.CommentViewModel
@using System.Linq
@if (ViewBag.User.Permissions.Contains("ReadComment"))
{
    <div class="page-header">
        <h2>
            Comments</h2>
        @if (ViewBag.User.Permissions.Contains("CreateComment"))
        {
            <a class="btn pull-right" data-toggle="modal" href="#comment-modal"><i class="icon-comment">
            </i>&nbsp;Comment</a>
        }
    </div>
    <div class="row comments">
        <div class="span9">
            @if (ViewBag.Comments != null && ViewBag.Comments.Count > 0)
            {
                foreach (var comment in ViewBag.Comments)
                {
                <div class="row comment">
                    <img class="span1" src="@Url.Content("../../Content/img/profile.png")" width="60" height="60">
                    <div class="span8">
                        <blockquote>
                            @if (ViewBag.User.Permissions.Contains("DeleteComment") || @comment.UserId == ViewBag.User.Id)
                            {
                                <a href="@Url.Action("Delete", "Comment", new { @commentId = @comment.Id })" class="pull-right confirm" title="Delete comment">
                                    <i class="icon-trash"></i></a>
                            }
                            <p>@comment.Comment</p>
                            <small><a href="@Url.Action("Index", "User", new { @userId = @comment.UserId })">@comment.UserName</a>
                                <time class="timeago" datetime="@comment.Created">@comment.Created</time>
                            </small>
                        </blockquote>
                    </div>
                </div>
                }
            }
            else
            {
                <p class="no-comments">
                    No comments yet</p>
            }
        </div>
    </div>
}
@if (ViewBag.User.Permissions.Contains("CreateComment"))
{
    <div class="modal fade hide" id="comment-modal">
        <div class="modal-header">
            <button class="close" data-dismiss="modal">
                &times;</button>
            <h3>
                Comment</h3>
        </div>
        @using (Html.BeginForm("Create", "Comment", FormMethod.Post, new { @class = "form-horizontal" }))
        {
            @Html.ValidationSummary(true)
            <div class="modal-body">
                @Html.TextAreaFor(model => model.Comment, new { @rows = 3, @placeholder = "Add new comment...", @autofocus = "autofocus" })
                <input name="MediaId" type="hidden" value="@ViewBag.Movie.Id">
                <input name="UserId" type="hidden" value="@ViewBag.User.Id">
            </div>
            <div class="modal-footer">
                <a href="#" class="btn" data-dismiss="modal">Cancel</a>
                <input type="submit" class="btn btn-primary" value="Add comment" />
            </div>
        }
    </div>
}